package com.leozhang.portalssm.service.impl;

import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.leozhang.portalssm.entity.Equipmentbrand;
import com.leozhang.portalssm.entity.Equipmentstatus;
import com.leozhang.portalssm.entity.EquipmentstatusExample;
import com.leozhang.portalssm.mapper.EquipmentstatusMapper;
import com.leozhang.portalssm.service.EquipmentStatusService;
import com.leozhang.portalssm.util.ChangeChar;
import com.leozhang.portalssm.util.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

@Transactional
@Service
public class EquipmentStatusImpl implements EquipmentStatusService {

    @Autowired
    private EquipmentstatusMapper equipmentstatusMapper;


    @Override
    public Result getListForPage(int pno, int psize, String statusName, String sortField, String sortType) {
        Page<Object> p = PageHelper.startPage(pno, psize);
        EquipmentstatusExample example = new EquipmentstatusExample();
        EquipmentstatusExample.Criteria criteria = example.createCriteria();
        if(statusName.trim().length()>0){
            criteria.andStatusNameLike("%"+statusName+"%");

        }
        if(sortField.trim().length()>0){
            example.setOrderByClause(ChangeChar.camelToUnderline(sortField,2) +""+sortType);
        }
        List<Equipmentstatus> list = equipmentstatusMapper.selectByExample(example);
        return Result.end(200,list,"查询成功",p.getTotal());

    }

    @Override
    public void insertequipmentstatus(Equipmentstatus equipmentstatus) {
        equipmentstatusMapper.insertSelective(equipmentstatus);
    }

    @Override
    public Equipmentstatus selectequipmentStatusById(Long id) {
        Equipmentstatus equipmentstatus = equipmentstatusMapper.selectByPrimaryKey(id);
        return equipmentstatus;
    }

    @Override
    public void updateEquipmentStatus(Equipmentstatus equipmentstatus) {
        equipmentstatusMapper.updateByPrimaryKeySelective(equipmentstatus);
    }

    @Override
    public void deleteequipmentstatusById(Long id) {
        equipmentstatusMapper.deleteByPrimaryKey(id);
    }

    @Override
    public List<Equipmentstatus> selectListAll() {
        return equipmentstatusMapper.selectByExample(null);
    }
}
